﻿<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8"/>
	<title>Financial Tracking</title>
	<script src="${pageContext.request.contextPath}/js/jquery.js" type="text/javascript"></script>
	<script src="${pageContext.request.contextPath}/js/jquery-ui.min.js" type="text/javascript"></script>
	<script src="${pageContext.request.contextPath}/js/global.js" type="text/javascript"></script>
	
	<link rel="stylesheet" href="${pageContext.request.contextPath}/css/jquery-ui.css" type="text/css"/>
	<link rel="stylesheet" href="${pageContext.request.contextPath}/css/styles.css" type="text/css"/>

	<script>
		$("head").append('<link rel="icon" type="image/icon" href="${pageContext.request.contextPath}/images/mini-icon.ico">');
	

		/* ------------------ Hospital Event ------------------- */
		var hospitalFirst = "กรุณาเลือกหน่วยบริการ";
		var unitAmount = 1000000;
		var province = "";
		var mapsAll = new Array();
		var oldRep = "";
		var isSearch = '${SESSION_SUMMARY.pageRepNo.search}';
		$(function(){
			var zoneId = "${SESSION_SUMMARY.pageRepNo.zone.zoneId}";
			var sessionHospitalCode = "${SESSION_SUMMARY.pageRepNo.hospital.hospitalCode}";
			var sessionProvinceCode = "${SESSION_SUMMARY.pageRepNo.province.provinceCode}";
			var sessionRepNo = "${SESSION_SUMMARY.pageRepNo.repNo}";
			$("#txtDataListReport").val(sessionRepNo);
			var lenHospitalCode = sessionHospitalCode.length;
			if(lenHospitalCode > 0){
				sessionHospitalCode = sessionHospitalCode.substring(lenHospitalCode -5, lenHospitalCode);
			}
			
			$(document).ready(function(){
				clearData(false);
				$("#cbxSelectAuthType").val('${SESSION_SUMMARY.pageRepNo.authTypeSelect}');
				if("${USER.officeCode}" === ""){
					$.ajax({
			            url : '${pageContext.request.contextPath}/master/getProvince',
			            type: "POST",
			            data: {zoneId: "${SESSION_SUMMARY.pageRepNo.zone.zoneId}"},
			            async: false,
			            success : function(data) {
							if(data.success){
								if(data.code === "0000"){
									datas = data.datas;
									var option = "";
									$.each(data.datas, function(key, value) {
										if(sessionProvinceCode === value.provinceCode){
											option += "<option value='"+value.provinceCode+"' selected>" + value.provinceName + "</option>";
										}else{
											option += "<option value='"+value.provinceCode+"'>" + value.provinceName + "</option>";
										}
									});
									$("#cbxProvince").html("");
									$("#cbxProvince").html(option);
									$.getHospital($("#cbxProvince").val(), false);
									
								}
							}else{
			            		$.alert("ERROR" + data.code, data.msg);
							}
			            }
			        });
		        }else{
					$.ajax({
			            url : '${pageContext.request.contextPath}/master/getProvinceByHospitalCode',
			            type: "POST",
			            data: {hospitalCode: "${USER.officeCode}"},
			            async: false,
			            success : function(data) {
							if(data.success){
								if(data.code === "0000"){
									datas = data.datas;
									var option = "<option value='"+datas.provinceCode+"' selected>" + datas.provinceName + "</option>";
									$("#cbxProvince").html("");
									$("#cbxProvince").html(option);
									$.getHospital($("#cbxProvince").val(), false);
									
								}
							}else{
			            		$.alert("ERROR" + data.code, data.msg);
							}
			            }
			        });
		        }
			});
			$("#cbxProvince").change(function(){
	       		$.getHospital($(this).val(), true);
	       	});	
			
			var lastDate = new Date();
			lastDate.setDate(lastDate.getDate() - 15);
			$("#fromDate").datepicker({
				buttonImage: "${pageContext.request.contextPath}/images/calendar.gif"
			});
			$("#fromDate").val(toDatepickerValue("${SESSION_SUMMARY.fromDateStr}"));
			$("#toDate").datepicker({
				buttonImage: "${pageContext.request.contextPath}/images/calendar.gif"
			});
			$("#toDate").val(toDatepickerValue("${SESSION_SUMMARY.toDateStr}"));
			
			$.getHospital = function(provinceId, async){
				province = provinceId;
				if("${USER.officeCode}" === ""){
					$.ajax({
			            url : '${pageContext.request.contextPath}/master/getHospital',
			            type: "POST",
			            async: async,
			            data: {zoneId: zoneId, provinceId: provinceId},
			            success : function(data) {
							if(data.success){
								if(data.code === "0000"){
									datas = data.datas;
									var option = "<option value='" + hospitalFirst + "' selected>" + hospitalFirst + "</option>";
									var selected = "";
									$.each(data.datas, function(key, value) {
										var len = value.hospitalCode.length;
										var hospitalCode = value.hospitalCode.substring(len -5, len);
										option += "<option value='" + hospitalCode + " - " + value.hospitalName + "'>" + hospitalCode + " - " + value.hospitalName + "</option>";
									});
									$("#txtDataListHospital").html("");
									$("#txtDataListHospital").html(option);
									$("#txtDataListHospital").combobox();
									$(".custom-combobox-input").focusin(function(){
										$(this).val("");
									});
									
									$(".custom-combobox-input").focusout(function(){
										var text = $("#txtDataListHospital option:selected" ).text();
										$(this).val(text);
									});
									if(isSearch === 'true'){
										var hCode = "${SESSION_SUMMARY.pageRepNo.hospital.hospitalCode}";
										var hName = "${SESSION_SUMMARY.pageRepNo.hospital.hospitalName}";
										var len = hCode.length;
										hCode = hCode.substring(len -5, len);
										$(".custom-combobox-input").val(hCode + ' - ' + hName);
										getRepNo($(".custom-combobox-input").val(), false, false);
									}
								}
							}else{
			            		$.alert("ERROR" + data.code, data.msg);
							}
			            }
			        });
		        }else{
					var option = "<option value='" + "${USER.officeCode}" + " - " + "${USER.officeName}" + "'>" + "${USER.officeCode}" + " - " + "${USER.officeName}" + "</option>";
					$("#txtDataListHospital").html("");
					$("#txtDataListHospital").html(option);
					$("#txtDataListHospital").combobox();
					$("a.ui-button").hide();
					$(".custom-combobox-input").focusout(function(e){
						$(this).val("${USER.officeCode}" + " - " + "${USER.officeName}");
					});
					getRepNo($(".custom-combobox-input").val(), false, false);
		        }
				
			};
			/* ------------------ End Hospital Event  ------------------- */			
			$("#btnSearch").click(function(){
				getRepNo($(".custom-combobox-input").val(), true, true);
			});
		});
		
		function getRepNo(value, async, click){
			var hospitalCode = "";
			if(value == null){
				hospitalCode = "";
			}else{
				var tmps = value.split("-");
				hospitalCode = tmps[0].trim();
			}
			
			var fromDate = $("#fromDate").val();
			var toDate = $("#toDate").val();
			
			if(fromDate === "" || toDate === ""){
				$.alert("", "โปรดระบุช่วงวันค้นหา");
				return;
			}
			
			fromDate = formatStrDate($("#fromDate").val());
			toDate = formatStrDate($("#toDate").val());
			if(!fromDate){
				$("#fromDate").focus();
				$.alert("", "โปรดระบุวันที่ให้ถูกต้องเช่น 01 มกราคม 2555");
				return;
			}
			if(!toDate){
				$("#toDate").focus();
				$.alert("", "โปรดระบุวันที่ให้ถูกต้องเช่น 01 มกราคม 2555");
				return;
			}
			
			if(!checkDate(fromDate, toDate)){
				$("#fromDate").val(toDatepickerValue("${SESSION_SUMMARY.fromDateStr}"));
				return;
			}
			
			if(hospitalCode === ""){
				$.alert("", "โปรดระบุข้อมูลเพื่อค้นหา");
				return;
			}
			var repNo = $("#txtDataListReport").val().trim();
			$("#txtDataListReport").val(repNo);
	        if(isSearch === 'true' || click === true){
				$.ajax({
		            url : '${pageContext.request.contextPath}/summary/details/getRepNo',
		            type: "POST",
		            async: async,
		            data: {hospitalCode: hospitalCode, provinceId: province, fromDate: formatStrDate($("#fromDate").val()), 
		            		toDate: formatStrDate($("#toDate").val()), repNo: repNo, authType: $("#cbxSelectAuthType").val()},
		            success : function(data) {
						if(data.success){
							if(data.code === "0000"){
								datas = data.datas;
								mappingRepNo(datas, false);
							}else{
		            			$.alert("", data.msg);
		            			clearData(false);
							}
						}else{
		            		$.alert("", data.msg);
						}
		            }
		        });
		      }
	        //}
		}
		
		function mappingRepNo(maps, searchDataRep){
		
			var userType = '${USER.userType}';
		
			var option = "";
			var divPatitionDatas = "";
			var amountPatition = 0;
			var countRepPatition = 0;
			
			var divCompensation = "";
			var amountCompensation = 0;
			var countRepCompensation = 0;
			
			var divBudget = "";
			var amountBudget = 0;
			var countRepBudget = 0;
			
			var divPayable = "";
			var amountPayable = 0;
			var countRepPayable = 0;
			
			var divTransfer = "";
			var amountTransfer = 0;
			var countRepTransfer = 0;
			
			var divProcessing = "";
			var amountProcessing = 0;
			var countRepProcessing = 0;
			
			
			var total = 0;
			var totalProcess = 0;
			var link = "${pageContext.request.contextPath}/summary/details/data?repNo=";
			mapsAll = maps;
			
			if(userType == "Employee"){
				$.each(maps, function(key, value) {
					$.each(value, function(i, val){
						//total += val.total;
						var amntTotal = parseFloat(currencyFormat(val.total/unitAmount));
						var amntAmount = parseFloat(currencyFormat(val.amount/unitAmount));
						total += amntAmount;
						var orfAmount = '';
						if(val.orfAmount !== '' && val.orfAmount !== 0){
							//orfAmount = ', ' + currencyFormat(val.orfAmount/unitAmount) + '(ORF)';
						}
						/*if(key === "compensation"){
							divCompensation += "<a href='" + link + val.repNo + "&status=compensation' id='rep_"+val.repNo
									+"' title='compensation' onclick='loadpage()'>" + val.repNo + "|" 
									+ currencyFormat(amntTotal) + "|"
									+ currencyFormat(val.hmainAmount/unitAmount) + "|" 
									+ currencyFormat(val.nhsoAmount/unitAmount) +"</a><br>";
							amountCompensation += amntTotal;
							total += amntTotal;
							countRepCompensation++;
						}else if(key === "patition"){
							divPatitionDatas += "<a href='" + link + val.repNo + "&status=patition' id='rep_"+val.repNo
									+"' title='patition' onclick='loadpage()'>" + val.repNo + "|" 
									+ currencyFormat(amntAmount) + "|"
									+ currencyFormat(val.hmainAmount/unitAmount) + "|" 
									+ currencyFormat(val.nhsoAmount/unitAmount) +"</a><br>";
							amountPatition += amntAmount;
							countRepPatition++;
						}else if(key === "budget"){
							divBudget += "<a href='" + link + val.repNo + "&status=budget' id='rep_"+val.repNo
									+"' title='budget' onclick='loadpage()'>" + val.repNo + "|" 
									+ currencyFormat(amntAmount) + "|"
									+ currencyFormat(val.hmainAmount/unitAmount) + "|" 
									+ currencyFormat(val.nhsoAmount/unitAmount) +"</a><br>";
							amountBudget += amntAmount;
							countRepBudget++;
						}else if(key === "payable"){
							divPayable += "<a href='" + link + val.repNo + "&status=payable' id='rep_"+val.repNo
									+"' title='payable' onclick='loadpage()'>" + val.repNo + "|" 
									+ currencyFormat(amntAmount) + "|"
									+ currencyFormat(val.hmainAmount/unitAmount) + "|" 
									+ currencyFormat(val.nhsoAmount/unitAmount) +"</a><br>";
							amountPayable += amntAmount;
							countRepPayable++;
						}else if(key === "transfer"){
							divTransfer += "<a href='" + link + val.repNo + "&status=transfer' id='rep_"+val.repNo
									+"' title='transfer' onclick='loadpage()'>" + val.repNo + "|" 
									+ currencyFormat(amntAmount) + "|" 
									+ currencyFormat(val.hmainAmount/unitAmount) + "|" 
									+ currencyFormat(val.nhsoAmount/unitAmount) +"</a><br>";
							amountTransfer += amntAmount;
							countRepTransfer++;
						}*/
						var hmain = val.hmainAmount > 0 ? currencyFormat(val.hmainAmount/unitAmount) : "-";
						var nhso = val.nhsoAmount > 0 ? currencyFormat(val.nhsoAmount/unitAmount) : "-";
						
						if(key === "compensation"){
							divCompensation += "<tr>";
							divCompensation += "<td width='26%' align='center' style='border-right: 1px solid #000000;border-left: 2px solid #000000;'><a href='" + link + val.repNo + "&status=compensation' id='rep_"+val.repNo
							+"' title='compensation' onclick='loadpage()'>" + val.repNo + "</a></td>"; 
							divCompensation += "<td width='27%' align='center' style='border-right: 1px solid #000000;border-left: 1px solid #000000;'>"+ currencyFormat(amntTotal) + "</td>"; 
							divCompensation += "<td  width='26%' align='center' style='border-right: 1px solid #000000;border-left: 1px solid #000000;'>" + hmain + "</td>"; 
							divCompensation += "<td align='center' style='border-left: 1px solid #000000;'>" + nhso + "</td>";
								
							//+ "</a><br>";
							divProcessing += "</tr>";
							amountCompensation += amntTotal;
							total += amntTotal;
							countRepCompensation++;
						}else if(key === "patition"){
							divPatitionDatas += "<tr>";
							divPatitionDatas += "<td width='26%' align='center' style='border-right: 1px solid #000000;border-left: 2px solid #000000;'><a href='" + link + val.repNo + "&status=patition' id='rep_"+val.repNo
							+"' title='patition' onclick='loadpage()'>" + val.repNo + "</a></td>"; 
							divPatitionDatas += "<td width='27%' align='center' style='border-right: 1px solid #000000;border-left: 1px solid #000000;'>"+ currencyFormat(amntAmount) + "</td>"; 
							divPatitionDatas += "<td  width='26%' align='center' style='border-right: 1px solid #000000;border-left: 1px solid #000000;'>" + hmain + "</td>"; 
							divPatitionDatas += "<td align='center' style='border-left: 1px solid #000000;'>" + nhso + "</td>";
								
							//+ "</a><br>";
							divPatitionDatas += "</tr>";
							amountPatition += amntAmount;
							countRepPatition++;
						}else if(key === "budget"){
							divBudget += "<tr>";
							divBudget += "<td width='26%' align='center' style='border-right: 1px solid #000000;border-left: 2px solid #000000;'><a href='" + link + val.repNo + "&status=budget' id='rep_"+val.repNo
							+"' title='budget' onclick='loadpage()'>" + val.repNo + "</a></td>"; 
							divBudget += "<td width='27%' align='center' style='border-right: 1px solid #000000;border-left: 1px solid #000000;'>"+ currencyFormat(amntAmount) + "</td>"; 
							divBudget += "<td  width='26%' align='center' style='border-right: 1px solid #000000;border-left: 1px solid #000000;'>" + hmain + "</td>"; 
							divBudget += "<td align='center' style='border-left: 1px solid #000000;'>" + nhso + "</td>";
								
							//+ "</a><br>";
							divProcessing += "</tr>";
							amountBudget += amntAmount;
							countRepBudget++;
						}else if(key === "payable"){
							divPayable += "<tr>";
							divPayable += "<td width='26%' align='center' style='border-right: 1px solid #000000;border-left: 2px solid #000000;'><a href='" + link + val.repNo + "&status=payable' id='rep_"+val.repNo
							+"' title='payable' onclick='loadpage()'>" + val.repNo + "</a></td>"; 
							divPayable += "<td width='27%' align='center' style='border-right: 1px solid #000000;border-left: 1px solid #000000;'>"+ currencyFormat(amntAmount) + "</td>";  
							divPayable += "<td  width='26%' align='center' style='border-right: 1px solid #000000;border-left: 1px solid #000000;'>" + hmain + "</td>"; 
							divPayable += "<td align='center' style='border-left: 1px solid #000000;'>" + nhso + "</td>";
								
							//+ "</a><br>";
							divPayable += "</tr>";
							amountPayable += amntAmount;
							countRepPayable++;
						}else if(key === "transfer"){
							divTransfer += "<tr>";
							divTransfer += "<td width='27%' align='center' style='border-right: 1px solid #000000;border-left: 2px solid #000000;'><a href='" + link + val.repNo + "&status=transfer' id='rep_"+val.repNo
							+"' title='transfer' onclick='loadpage()'>" + val.repNo + "</a></td>"; 
							divTransfer += "<td width='26%' align='center' style='border-right: 1px solid #000000;border-left: 1px solid #000000;'>"+ currencyFormat(amntAmount) + "</td>"; 
							divTransfer += "<td  width='26%' align='center' style='border-right: 1px solid #000000;border-left: 1px solid #000000;'>" + hmain + "</td>"; 
							divTransfer += "<td align='center' style='border-left: 1px solid #000000;'>" + nhso + "</td>";
								
							//+ "</a><br>";
							divTransfer += "</tr>";
							amountTransfer += amntAmount;
							countRepTransfer++;
						}
						
						option += "<option value='" + val.repNo + "'/>";
					});
				});
				totalProcess = amountCompensation + amountPatition + amountBudget;
				$("#dataListReport").html(option);
				
				
				if(divCompensation !== ""){
					var tmp = "<table cellpadding='0' cellspacing='0' width='100%'>" + divCompensation + "</table>";
					$("#compensation").html(tmp);
				}else{
					$("#compensation").html(divCompensation);
				}
				if(divPatitionDatas !== ""){
					var tmp = "<table cellpadding='0' cellspacing='0' width='100%'>" + divPatitionDatas + "</table>";
					$("#patition").html(tmp);
				}else{
					$("#patition").html(divPatitionDatas);
				}
				if(divBudget !== ""){
					var tmp = "<table cellpadding='0' cellspacing='0' width='100%'>" + divBudget + "</table>";
					$("#budget").html(tmp);
				}else{
					$("#budget").html(divBudget);
				}
				
				//$("#compensation").html(divCompensation);
				//$("#patition").html(divPatitionDatas);
				//$("#budget").html(divBudget);
				$("#totalPatition").html(currencyFormat(amountPatition));						
				$("#totalProcess").html(currencyFormat(totalProcess));						
				$("#totalBudget").html(currencyFormat(amountBudget));
				$("#totalCompensation").html(currencyFormat(amountCompensation));
				
				$("#totalRepCompensation").html(countRepCompensation);
				$("#totalRepPatition").html(countRepPatition);
				$("#totalRepBudget").html(countRepBudget);
			}else{
				$.each(maps, function(key, value) {
					$.each(value, function(i, val){
						var amntTotal = parseFloat(currencyFormat(val.total/unitAmount));
						var amntAmount = parseFloat(currencyFormat(val.amount/unitAmount));
						total += amntAmount;
						var orfAmount = '';
						if(val.orfAmount !== '' && val.orfAmount !== 0){
							//orfAmount = ', ' + currencyFormat(val.orfAmount/unitAmount) + '(ORF)';
						}
						
						var hmain = val.hmainAmount > 0 ? currencyFormat(val.hmainAmount/unitAmount) : "-";
						var nhso = val.nhsoAmount > 0 ? currencyFormat(val.nhsoAmount/unitAmount) : "-";
						//total += val.amount;
							if(key === "compensation"){
								divProcessing += "<tr>";
								divProcessing += "<td width='26%' align='center' style='border-right: 1px solid #000000;border-left: 2px solid #000000;'><a href='" + link + val.repNo + "&status=compensation' id='rep_"+val.repNo
								+"' title='compensation' onclick='loadpage()'>" + val.repNo + "</a></td>"; 
								divProcessing += "<td width='26%' align='center' style='border-right: 1px solid #000000;border-left: 1px solid #000000;'>"+ currencyFormat(amntTotal) + "</td>"; 
								divProcessing += "<td  width='26%' align='center' style='border-right: 1px solid #000000;border-left: 1px solid #000000;'>" + hmain + "</td>"; 
								divProcessing += "<td align='center' style='border-left: 1px solid #000000;'>" + nhso + "</td>";
									
								//+ "</a><br>";
								divProcessing += "</tr>";
								amountProcessing += amntTotal;
								total += amntTotal;
								countRepProcessing++;
							}else if(key === "patition"){
								divProcessing += "<tr>";
								divProcessing += "<td width='26%' align='center' style='border-right: 1px solid #000000;border-left: 2px solid #000000;'><a href='" + link + val.repNo + "&status=compensation' id='rep_"+val.repNo
								+"' title='compensation' onclick='loadpage()'>" + val.repNo + "</a></td>"; 
								divProcessing += "<td width='26%' align='center' style='border-right: 1px solid #000000;border-left: 1px solid #000000;'>"+ currencyFormat(amntAmount) + "</td>"; 
								divProcessing += "<td  width='26%' align='center' style='border-right: 1px solid #000000;border-left: 1px solid #000000;'>" + hmain + "</td>"; 
								divProcessing += "<td align='center' style='border-left: 1px solid #000000;'>" + nhso + "</td>";
									
								//+ "</a><br>";
								divProcessing += "</tr>";
								amountProcessing += amntAmount;
								countRepProcessing++;
							}else if(key === "budget"){
								divProcessing += "<tr>";
								divProcessing += "<td width='26%' align='center' style='border-right: 1px solid #000000;border-left: 2px solid #000000;'><a href='" + link + val.repNo + "&status=compensation' id='rep_"+val.repNo
								+"' title='compensation' onclick='loadpage()'>" + val.repNo + "</a></td>"; 
								divProcessing += "<td width='26%' align='center' style='border-right: 1px solid #000000;border-left: 1px solid #000000;'>"+ currencyFormat(amntAmount) + "</td>"; 
								divProcessing += "<td  width='26%' align='center' style='border-right: 1px solid #000000;border-left: 1px solid #000000;'>" + hmain + "</td>"; 
								divProcessing += "<td align='center' style='border-left: 1px solid #000000;'>" + nhso + "</td>";
									
								//+ "</a><br>";
								divProcessing += "</tr>";
								amountProcessing += amntAmount;
								countRepProcessing++;
							}else if(key === "payable"){
								divPayable += "<tr>";
								divPayable += "<td width='26%' align='center' style='border-right: 1px solid #000000;border-left: 2px solid #000000;'><a href='" + link + val.repNo + "&status=payable' id='rep_"+val.repNo
								+"' title='payable' onclick='loadpage()'>" + val.repNo + "</a></td>"; 
								divPayable += "<td width='26%' align='center' style='border-right: 1px solid #000000;border-left: 1px solid #000000;'>"+ currencyFormat(amntAmount) + "</td>";  
								divPayable += "<td  width='26%' align='center' style='border-right: 1px solid #000000;border-left: 1px solid #000000;'>" + hmain + "</td>"; 
								divPayable += "<td align='center' style='border-left: 1px solid #000000;'>" + nhso + "</td>";
									
								//+ "</a><br>";
								divPayable += "</tr>";
								amountPayable += amntAmount;
								countRepPayable++;
							}else if(key === "transfer"){
								divTransfer += "<tr>";
								divTransfer += "<td width='26%' align='center' style='border-right: 1px solid #000000;border-left: 2px solid #000000;'><a href='" + link + val.repNo + "&status=transfer' id='rep_"+val.repNo
								+"' title='transfer' onclick='loadpage()'>" + val.repNo + "</a></td>"; 
								divTransfer += "<td width='26%' align='center' style='border-right: 1px solid #000000;border-left: 1px solid #000000;'>"+ currencyFormat(amntAmount) + "</td>"; 
								divTransfer += "<td  width='26%' align='center' style='border-right: 1px solid #000000;border-left: 1px solid #000000;'>" + hmain + "</td>"; 
								divTransfer += "<td align='center' style='border-left: 1px solid #000000;'>" + nhso + "</td>";
									
								//+ "</a><br>";
								divTransfer += "</tr>";
								amountTransfer += amntAmount;
								countRepTransfer++;
							}
							option += "<option value='" + val.repNo + "'/>";
						});
						
						totalProcess = amountProcessing;
						
						$("#totalProcess").html(currencyFormat(totalProcess));				
						
						$("#dataListReport").html(option);
				
						if(divProcessing !== ""){
							var tmp = "<table cellpadding='0' cellspacing='0' width='100%'>" + divProcessing + "</table>";
							$("#processing").html(tmp);
						}else{
							$("#processing").html(divProcessing);
						}
						$("#totalProcessing").html(currencyFormat(amountProcessing));
						$("#totalRepProcessing").html(countRepProcessing);	
				});
			
			}
			
			if(divPayable !== ""){
				var tmp = "<table cellpadding='0' cellspacing='0' width='100%'>" + divPayable + "</table>";
				$("#payable").html(tmp);
			}else{
				$("#payable").html(divPayable);
			}
			if(divTransfer !== ""){
				var tmp = "<table cellpadding='0' cellspacing='0' width='100%' style='margin-left: 1px;'>" + divTransfer + "</table>";
				$("#transfer").html(tmp);
			}else{
				$("#transfer").html(divTransfer);
			}
			$(".totalPayable").html(currencyFormat(amountPayable));
			$("#totalRepPayable").html(countRepPayable);
			
			$(".totalTransfer").html(currencyFormat(amountTransfer));
			$("#totalRepTransfer").html(countRepTransfer);
			
			
			
			if(!searchDataRep){
				$("#total").html(currencyFormat(total));
				//$("#payTotal").html(currencyFormat((totalProcess + amountPayable + amountTransfer)/unitAmount));
				$("#payTotal").html(currencyFormat(amountTransfer));
			}
		}
		
		function clearData(searchByRep){
			if(!searchByRep){
				$("#total").html(currencyFormat(0));
				$("#payTotal").html(currencyFormat(0));
			}
			$("#totalPatition").html("");
			
			$("#compensation").html("");
			$("#patition").html("");
			$("#budget").html("");
			$("#totalPatition").html(currencyFormat(0));
			$("#totalRepPatition").html(0);						
			$("#totalProcess").html(currencyFormat(0));						
			$("#totalBudget").html(currencyFormat(0));
			$("#totalRepBudget").html(0);
			$("#totalCompensation").html(currencyFormat(0));
			$("#totalRepCompensation").html(0);
			
			$("#processing").html("");
			$("#totalProcessing").html(currencyFormat(0));
			$("#totalRepProcessing").html(0);
			
			$("#payable").html("");
			$(".totalPayable").html(currencyFormat(0));
			$("#totalRepPayable").html(0);
			$("#transfer").html("");
			$(".totalTransfer").html(currencyFormat(0));
			$("#totalRepTransfer").html(0);
			
			
		}
	</script>
	
	<style>
		.ui-autocomplete {
		    max-height: 350px;
		    overflow-y: auto;
		    width: 300px;
		    overflow-x: auto;
		  }
		  /* IE 6 doesn't support max-height
		   * we use height instead, but this forces the menu to always be this tall
		   */
		  * html .ui-autocomplete {
		    height: 350px;
		    width: 300px;
		  }
		/************************* Panel ***************************/
		
	
		.content{
			width: 100%;
		}
		.content div.panel-block{
			float: left;
			overflow: visible;
		}
	</style>
</head>

<body>
	<!------------------- Header ------------------>
    <div class="panel">
    	<jsp:include page="../include/header.jsp"/>
    </div>
    <!--------------------------------------------->
	
    <div class="block-content">
    	<jsp:include page="../include/breadcrumb.jsp"/>

        <div id="content" class="content-data">
        	<!-- Content Data -->
            <div class="panel">
                <div class="panel-content text-center">
                	${SESSION_SUMMARY.pageRepNo.zone.zoneName}&nbsp;&nbsp;
                    <select id="cbxProvince" class="dropdownlist"></select>
                    &nbsp;&nbsp;โรงพยาบาล&nbsp;
                    <select id="txtDataListHospital"></select>
                    &nbsp;Rep No.&nbsp;
                    <input class="input-control text" list="dataListReport" id="txtDataListReport" style="width: 150px">
                    <datalist id="dataListReport">
                    </datalist><br><br>
					แฟ้มการเบิกกองทุน:&nbsp;<select id="cbxSelectAuthType" class="dropdownlist" style="width: 250px">
						<option value="">ทั้งหมด</option>
						<option value="UC">งบหลักประกันสุขภาพถ้วนหน้า (UC)</option>
						<option value="LGO">องค์การปกครองส่วนท้องถิ่น (LGO)</option>
					</select>
                	ข้อมูลจากวันที่&nbsp;
                    <input type="text" id="fromDate">
                    &nbsp;ถึงวันที่&nbsp;
                    <input type="text" id="toDate">
                    <button id="btnSearch">ค้นหา</button>
                </div>
            </div>
            <div class="panel bg-main">
				<div class="text-center" style="font-weight: bold">
					ยอดพึงรับทั้งหมด <span id="total"></span> ล้านบาท / สปสช.จ่าย <span id="payTotal"></span> ล้านบาท
				</div>
           	</div>
            <div class="content">
           <c:choose>
	           <c:when test="${USER.userType eq 'Hospital'}">
	           		<%@include  file="./summaryTrackStationHospital.jsp" %> 
	           </c:when>
	           <c:otherwise>
	           		<%@include  file="./summaryTrackStationEmployee.jsp" %> 
	           </c:otherwise>
            </c:choose>
            </div>
        </div>
    </div>
</body>
</html>